I wrote the source code for this program in C++ to solve the quadratic equation. It is a simple program, console based. It compiled and ran with the free Borland C++ compiler.

quadratic.cpp


// quadratic.cpp
//
// This program solves a quadratic equation in standard form.
// The program prompts the user for three values -- A, B, and C,
// which correspond to the coefficients of a quadratic equation
// in standard form:
//
//              Ax^2 + Bx + C = 0
//
// Console-based
// Retruns real as well as comples roots.
//
// copyright: Jose M. Blanco, 2002
#include <stdio.h>
#include <iostream.h>
#include <math.h>

// function to evaluate the determinant
double determinant(double arg_a, double arg_b, double arg_c) {
   return (arg_b * arg_b) - (4 * arg_a * arg_c);
} // end determinant

// function to evaluate real roots
void realRoots(double arg_a, double arg_b, double arg_sqrt) {
         double firstRoot =        (-arg_b/(2 * arg_a)) +
                                                        (arg_sqrt/(2 * arg_a));
         double secondRoot = (-arg_b/(2 * arg_a)) -
                                                        (arg_sqrt/(2 * arg_a));
         cout << "\nFirst Real Root: \t" << firstRoot << "\n";
         cout << "Second Real Root: \t" << secondRoot << "\n";
} // end realRoots

void output1(double first, double second) {
         cout << "\nFirst Imaginary Root: \t" << first << " + " << second << "i" << "\n";
         cout << "\nSecond Imaginary Root: \t" << first << " - " << second << "i" << "\n";
} // end output1()

void output2(double first, double second) {
         second = -(second); // change the sign of the second term, for correct output
         cout << "\nFirst Imaginary Root: \t" << first << " - " << second << "i" << "\n";
         cout << "\nSecond Imaginary Root: \t" << first << " + " << second << "i" << "\n";
} // end output2()

// evaluate imaginary roots
void imaginaryRoots(double arg_a, double arg_b, double arg_imag_sqrt) {
        double two_a = 2 * arg_a;
        double first_term = (-arg_b)/two_a;
        double second_term = (arg_imag_sqrt)/two_a;

        if(second_term >= 0) {
                //cout << "\nsecond_term is greater than or eaqual to 0: " << second_term << "\n";
                output1(first_term, second_term);
        } // end if
        else {
                //cout << "\nsecond_term is less than or eaqual to 0: " << second_term << "\n";
                output2(first_term, second_term);
        } // end else

} // end imaginaryRoots

// main function
int main()
{
   cout << "\n***********************************************************************\n";
   cout << "*      Find the roots of a quadratic equation in standard form.       *";
   cout << "\n***********************************************************************\n";

   // declare variables a, b, and c
   double a, b, c;
   char n;

   do {
        cout << "\nEnter the value of 'a': ";
        cin  >> a;
        cout << "Enter the value of 'b': ";
        cin  >> b;
        cout << "Enter the value of 'c': ";
        cin  >> c;

        double det = determinant(a, b, c);

        if (det >= 0) {
                realRoots(a, b, sqrt(det));  // roots are real
        } // end if
        else {
                imaginaryRoots(a, b, sqrt(-det)); // roots are imaginary
        } // end else

        cout << "\nWould you like to solve another?";
        cout << "\nEnter 'y' for 'Yes' -- 'n' for 'No': ";
        cin  >> n;
        cout << "\n";

   } while (n == 'y' || n == 'Y'); // end do-while loop

return 0;
}